package com.cheli.managerAsset.controller;


import com.cheli.commonutils.R;
import com.cheli.managerAsset.entity.AsCategory;
import com.cheli.managerAsset.entity.subject.OneCategory;
import com.cheli.managerAsset.service.AsCategoryService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * <p>
 * 资产分类 前端控制器
 * </p>
 *
 * @author cheli
 * @since 2021-03-14
 */
@RestController
@RequestMapping("/asManager/category")
@Api(value = "category", tags = "资产分类管理")
@CrossOrigin
@Slf4j
public class AsCategoryController {
    @Autowired
    private AsCategoryService asCategoryService;

   //获取上传过来的文件，把文件内容读取出来
    @PostMapping("addCategory")
    public R addCategory(@RequestParam(value = "file",required = false) MultipartFile multipartFile){
        asCategoryService.saveCategory(multipartFile, asCategoryService);
        log.info("新增分类");
        return R.ok();
    }

   @GetMapping("tree")
    public R getCategoryTree(){
        List<OneCategory> list = asCategoryService.getAllCategory();
        log.info("查询资产分类");
        return R.ok().data("list",list);
    }

    @GetMapping("getCategoryAll")
    public R getCategoryAll(){
        log.info("查询资产分类全部信息");
        List<AsCategory> list = asCategoryService.list(null);
        return R.ok().data("list",list);
    }
}

